"""
http://spider.wangluozhe.com/challenge/4
var eval_ = eval
var eval = function (a) {
    debugger
    return eval_(a)
}
使用eval hook
"""
import time
import execjs
import requests

with open("js_4.js","r")as f:
    q=f.read()


url = "http://spider.wangluozhe.com/challenge/api/4"
item = []
sum = 0
for i in range(1, 101):

    sign = execjs.compile(q)
    data = {
        "page": i,
        "count": 10,
        "_signature": sign.call("a")
    }
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36",
        "Cookie": "session=c16127e4-c005-48eb-8399-84ad38f44e1c.TFoGW0vgru3R_xRmRhkAW2LHFwk",
        "Host": "spider.wangluozhe.com",
        "Origin": "http://spider.wangluozhe.com",
        "Referer": "http://spider.wangluozhe.com/challenge/4"
    }
    for i in range(3):
        res = requests.post(url=url, headers=headers,data=data)
        if res.status_code == 200:
            try:
                data_json = res.json().get("data")
                for i in data_json:
                    value = i.get("value")
                    print(f"当前数值为{value}")
                    sum += value
                break
            except Exception as e:
                print(f"当前页面无数据，展示为{res.text}")
                time.sleep(1)
                continue
    else:
        print("请求失败")
    time.sleep(0.75)
print(f"总数为{sum}")